
package net.biaji.android.alephclient;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class BootReceiver extends BroadcastReceiver {

    private final int CHECK_TIME = 9;

    @Override
    public void onReceive(Context context, Intent intent) {
        AlarmManager am = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE);
        Intent checkIntent = new Intent(context, ExpireCheckReceiver.class);
        PendingIntent pi = PendingIntent.getBroadcast(context, 1, checkIntent, 0);

        Calendar today = Calendar.getInstance();
        int year = today.get(Calendar.YEAR);
        int month = today.get(Calendar.MONTH);
        int day = today.get(Calendar.DATE);

        Calendar cal = Calendar.getInstance();
        cal.set(year, month, day, CHECK_TIME, 0);

        am.setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                pi);

        context.registerReceiver(new ExpireCheckReceiver(), new IntentFilter());
    }

}
